home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qx16comm.aqm / qx16comm.asm
Assembly Source File  |  1985-11-08  |  4KB  |  145 lines

  1.     page     60,132
  2.     title    QX16 MS-DOS RECEIVE INTERUPT DRIVER
  3.  
  4. ;    Chuck Freeman - Technical Support Manager - Great Northern Epson
  5. ;                       (612) 559-0992 ext 42
  6. ;
  7. ;    30 Jul 85   Version 1.00  -  Initial release  
  8.  
  9.  
  10.         comment *
  11.  
  12. This routine will install a RS-232 receive interupt driver with a 32K buffer
  13. for the Epson QX-16 operating under the MS-DOS 2.11 environment. This is just
  14. a demonstration program and does not contain code for the following possible
  15. error conditions:
  16.  
  17.     1. Receive Buffer Overflow
  18.     2. Parity Error
  19.     3. Framming Error
  20.         4. Overrun Error    
  21.  
  22. The Epson QX-16 utilizes a NEC 7201 Multi-Protocol Serial Controller chip
  23. (register/command compatible with the INTEL 8274 and ZILOG SIO chips) for
  24. the operation of the keyboard and RS-232 port. Port A of the 7201 is for
  25. keyboard operation and Port B is for RS-232 operation.
  26.  
  27.         *
  28.  
  29. ;******************************************************************************
  30. ; The 8259 master and 8259 slave interupt controller vector table is located
  31. ; starting at address 0000:01C0 and ending at address 0000:01FF. The 7201
  32. ; serial device chip handles the keyboard and the rs232 port. When either
  33. ; device causes an interupt, an INT 70 (address 0000:01C0) is executed. The
  34. ; purpose of this routine is to determine which device (keyboard or rs232)
  35. ; caused the interupt, and branch to the proper routine to service the
  36. ; interupting device.
  37. ;
  38. ; INT 7E (address 0000:01F8) is a vector pointing to the keyboard decoded
  39. ; interupt routine.
  40. ;
  41. ; INT 7F (address 0000:01FC) is a vector pointing to the rs232 decoded
  42. ; interupt routine. In the current production release of the qx-16, if you
  43. ; trace this routine with DEBUG, the actual routine does a IRET. This section
  44. ; of code will change the INT 7F vector to point to our rs232 interupt handler
  45. ; and make resident within the ms-dos environment our interupt handler code.
  46. ; We will utilize standard ms-dos function requests to do this.
  47.  
  48. code_segment    segment
  49.  
  50.     assume    cs:code_segment,ds:code_segment
  51.  
  52. start:    
  53.     cli                ;disable interupts
  54.  
  55.     mov    ax,code_segment        ;get code segment
  56.     mov    ds,ax            ;and set data segment to same
  57.  
  58.  
  59.     mov    ah,025h            ;select vector function
  60.     mov    al,07fh            ;select rs232 decoded interupt vector
  61.     mov    dx,offset decoded_rs232    ;point to our actual routine
  62.     int    021h            ;set the new vector
  63.  
  64.     mov    al,001h
  65.     out    013h,al            ;point to sio write register 1
  66.     mov    al,010h
  67.     out    013h,al            ;enable rs232 int on all rx char
  68.  
  69.     sti                ;enable interupts
  70.  
  71.     mov    ah,009h
  72.     mov    dx,offset message
  73.     int    021h
  74.  
  75.  
  76.     mov    ah,031h            ;select terminate but stay resident
  77.     mov    dx,interupt_length      ;set our code length in paragraphs
  78.     int    021h            ;do it and exit to ms-dos
  79.  
  80. message:
  81.     db    'RS-232 Interupt Driver Installed And Operational'
  82.     db    00dh,00ah,'$'
  83.  
  84.  
  85. ;****************************************************************************
  86.  
  87. interupt_begin    equ    $
  88.  
  89. decoded_rs232:
  90.  
  91.     sti
  92.     mov    ax,code_segment         ;get code segment
  93.     mov    ds,ax            ;and set data segment to same
  94.     push    bx
  95.     in    al,011h            ;get the received character
  96.     mov    si,offset receive_buffer;get put buffer pointer
  97.     mov    bx,[put_pointer]    ;save received character
  98.     mov    [bx+si-1],al
  99.     inc    bx
  100.     mov    [put_pointer],bx
  101.     pop    bx
  102.     mov    al,bl            ;get bios saved rr0 status
  103.     test    al,00000100b        ;test transmbit buffer empty interupt
  104.     jnz    continue        ;false - so do not reset tbe interupt
  105.     mov    al,028h
  106.     out    013h,al            ;rest transmit buffer empty interupt
  107.  
  108. continue:
  109.     cli                ;disable interupts
  110.     mov    al,030h
  111.     out    013h,al            ;reset sio errors
  112.     mov    al,010h
  113.     out    013h,al            ;reset external/status errors
  114.  
  115.     mov    al,038h
  116.     out    013h,al            ;sio end of interupt
  117.  
  118.     sti                ;enable interupts
  119.  
  120.     pop    ax            ;get ip off of stack from int 7f
  121.     pop    bx            ;get cs off of stack from int 7f
  122.     popf                ;get flags off of stack from int 7f
  123.     stc                ;set carry for bios routine
  124.     pushf                ;save flags for iret from int 7f
  125.     push    bx            ;save cs for iret from iret 7f
  126.     push    ax            ;save ip for iret from iret 7f
  127.  
  128.     iret                ;all done
  129.  
  130.  
  131. put_pointer    label    word
  132.         dw    00001h
  133.  
  134. receive_buffer    label    byte
  135.         db    08000h dup (?)
  136.  
  137. interupt_end    equ    $
  138. interupt_length    equ    (((interupt_end-interupt_begin)/010h)+1)
  139.  
  140. ;-----------------------------------------------------------------------------
  141.  
  142. code_segment    ends
  143.  
  144.     end    start
  145.